﻿//
package ICode.name.ui{
	//
	import flash.display.Sprite;
	import flash.display.DisplayObject ;
	import flash.display.BitmapData ;
	import flash.display.Bitmap ;
	import flash.events.Event ;
	import ICode.name.net.QueLoader ;
	import fl.controls.UIScrollBar;
	import fl.controls.ScrollBarDirection;
	//
	public class BigBitmapLoader extends Sprite {
		//
		private var m_obBmp :BigScrollBitmap = new BigScrollBitmap();
		private var m_obScrollBar :UIScrollBar = new UIScrollBar ();
		private var m_obHScrollBar :UIScrollBar = new UIScrollBar ();
		private var m_obLoader:QueLoader ;
		private var m_nLines:int = 0 ;
		private var m_nColumns :int = 0 ;
		private var m_nCellWidth:int = 0 ;
		private var m_nCellHeight:int = 0 ;
		private var m_nLoadNst :int = 0;
		private var m_arrData:Array ;
		//
		//∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥构造函数
		public function BigBitmapLoader() {
			m_obLoader = new QueLoader (this );
			m_obScrollBar.scrollTarget = m_obBmp.textField ;
			m_obHScrollBar.scrollTarget = m_obBmp.textField ;
			super.addChild(m_obBmp );
			super.addChild(m_obScrollBar );
			super.addChild(m_obHScrollBar );
			m_obHScrollBar.direction = ScrollBarDirection.HORIZONTAL ;
		}
		//∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥数据加载函数
		public function load(xml:XML ):void {
			if (xml!=null) {
				m_nLines = xml.@lines;
				m_nColumns = xml.@cols;
				var path:String = xml.@path;
				var post:String = xml.@post ;
				m_nLoadNst = 0 ;
				m_obLoader.addEventListener(Event.COMPLETE,complete_obLoader);
				m_arrData = [] ;
				for (var i:uint = 0; i<m_nLines; i++) {
					m_arrData.push([] ) ;
					for (var j:uint =0; j<m_nColumns; j++) {
						var str:String = path + "_0" + String(i+1) + "_0" + String(j+1) + post ;
						m_obLoader.addItem(str , addCell );
					}
				}
				m_obLoader.load() ;
			}
		}
		//∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥单元数据添加函数
		private function addCell(obj:DisplayObject):void {
			var obBmp:Bitmap = obj as Bitmap ;
			if(m_arrData!=null && obBmp !=null ) {
				m_nCellWidth = obj.width ;
				m_nCellHeight = obj.height ;
				var cols:int = m_nLoadNst / m_nColumns ;
				m_arrData[cols].push(obBmp.bitmapData ) ;
				m_nLoadNst ++ ;
			}
		}
		//∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥加载完成函数
		private function complete_obLoader(e:Event):void {
			m_obLoader.removeEventListener(Event.COMPLETE,complete_obLoader);
			var obData:BigBitmapData = new BigBitmapData();
			obData.data = m_arrData ;
			m_obBmp.bitmapData = obData ;
			m_obBmp.width = this.width ;
			m_obBmp.height = this.height ;
			obData.scroll(0 , 0);
			dispatchEvent(new Event(Event.COMPLETE )) ;
		}
		//∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥数据获取函数
		public function get lines():int{return m_nLines};
		public function get columns():int{return m_nColumns } ;
		public function get cellWidth():int{return m_nCellWidth } ;
		public function get cellHeight():int{return m_nCellHeight } ;
		public function get dataWidth():int{return m_nCellWidth * m_nColumns } ;
		public function get dataHeight():int{return m_nCellHeight * m_nLines } ;
		//∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥宽度覆盖函数
		public override function set width(value:Number):void {
			m_obScrollBar.x = value - m_obScrollBar.width ;
			m_obBmp.width = m_obHScrollBar.width = m_obScrollBar.x ;
		}
		//∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥高度覆盖函数
		public override function set height(value:Number):void {
			m_obHScrollBar.y = value - m_obHScrollBar.height ;
			m_obBmp.height = m_obScrollBar.height =  m_obHScrollBar.y ;
		}
		//∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥
	}
}


